package vo.community
{
	import flash.utils.Dictionary;
	
	import mx.collections.ArrayCollection;
	
	public class CommunityFamilyStrategy implements CommunityStrategy
	{
		/**ma collection d'enfants*/
		private var _children:ArrayCollection;
		
		/**mon dico d'enfants key:category*/
		private var _childrenDic:Dictionary;
		
		public function CommunityFamilyStrategy()
		{
		}
		
		public function addChild(pCommunity:CommunityVO):void
		{
			if(pCommunity)
			{
				if(pCommunity.isKind())
				{
					if(!childrenDic[pCommunity.kind])
					{
						childrenDic[pCommunity.kind] = pCommunity;
						children.addItem(pCommunity);
					}
					else
					{
						removeChild(pCommunity);
						addChild(pCommunity);
					}
				}
				/*else
				{
					PAS DE NIVEAU EN DESSOUS DE KIND
					
					if(pCommunity.kind != null)
					{
						var myChild:CommunityVO = childrenDic[pCommunity.kind] as CommunityVO;
						
						if(myChild)
						{
							myChild.addChild(pCommunity);
						}
					}
					
				}*/
			}
		}
		
		public function removeChild(pCommunity:CommunityVO):void
		{
			if(pCommunity)
			{
				if(pCommunity.isKind() && childrenDic[pCommunity.kind])
				{
					children.removeItemAt(children.getItemIndex(childrenDic[pCommunity.kind]));
					delete childrenDic[pCommunity.kind];
				}
				/*else
				{
					PAS DE NIVEAU EN DESSOUS DE KIND
					
					if(pCommunity.kind != null)
					{
						var myChild:CommunityVO = childrenDic[pCommunity.kind] as CommunityVO;
						
						if(myChild)
						{
							myChild.removeChild(pCommunity);
						}
					}
				
				}*/
			}
		}
		
		public function get children():ArrayCollection
		{
			if(!_children)
				_children = new ArrayCollection();
			
			return _children;
		}
		
		public function get childrenDic():Dictionary
		{
			if(!_childrenDic)
				_childrenDic = new Dictionary(true);
			return _childrenDic;
		}
	}
}